<template>
  <section>
    <a-form-item name="roomNumber">
      <a-input-search
        v-model="state.roomnumber"
        :style="{ width: '320px' }"
        placeholder="Please enter something"
        @search="searchRoom"
        search-button
      />
    </a-form-item>
    <el-table :data="state.dataList" border stripe>
      <el-table-column
        width="50"
        label="序号"
        align="center"
        type="index"
      ></el-table-column>
      <el-table-column
        label="宿舍号码"
        prop="dormNumber"
        align="center"
      ></el-table-column>
      <el-table-column
        label="宿舍楼层"
        prop="dormFloor"
        align="center"
      ></el-table-column>
      <el-table-column
        label="宿舍人数"
        prop="survivorNumber"
        align="center"
      ></el-table-column>
      <el-table-column
        label="宿舍卫生情况"
        prop="hygienicCondition"
        align="center"
      ></el-table-column>
      <el-table-column
        label="宿舍荣誉"
        prop="roomHonors"
        align="center"
      ></el-table-column>
      <el-table-column label="操作" align="center">
        <template v-slot="scope">
          <el-button
            @click="toEdit(scope.row.id)"
            type="primary"
            status="warning"
            >申请调宿
          </el-button>
          <a-modal
            v-model:visible="visible"
            @ok="handleOk(form, scope.row)"
            @cancel="handleCancel"
          >
            <template #title>修改用户</template>
            <div>
              <a-row :gutter="16">
                <a-col :span="16">
                  <a-form-item
                    field="调宿理由"
                    label="调宿理由"
                    label-col-flex="100px"
                  >
                    <a-textarea
                      style="width: 320px; height: 100px"
                      v-model="form_a.reason"
                      placeholder="内容"
                      allow-clear
                    />
                  </a-form-item>
                </a-col>
              </a-row>
            </div>
          </a-modal>
        </template>
      </el-table-column>
    </el-table>
  </section>
</template>
<script setup lang="ts">
import { reactive, ref } from "vue";
import {
  Apply,
  ApplyControllerService,
  Room,
  RoomControllerService,
  UserControllerService,
} from "../../../generated";
import message from "@arco-design/web-vue/es/message";
import { useStore } from "vuex";

const form = reactive({
  dormFloor: undefined,
  dormNumber: "",
  dormSnumber: undefined,
  hygienicCondition: "",
  id: undefined,
  roomDorm: undefined,
  roomHonors: "",
  survivorNumber: undefined,
} as Room);

const form_a = reactive({
  applyTime: "",
  fromDorm: "",
  id: undefined,
  reason: "",
  state: "",
  studentId: undefined,
  toDorm: "",
} as Apply);
const state = reactive({
  roomnumber: null,
  dataList: [],
  // 请求参数
  query: {
    params: {
      current: 1,
      size: 10,
    },
  },
  // loading
});
const store = useStore();
const visible = ref(false);
const getDataList = () => {
  let current = state.query.params.current;
  let size = state.query.params.size;
  RoomControllerService.listPageUsingPost1(current, size)
    .then((res) => {
      let datas = res.data.records;
      state.dataList = datas;
    })
    .catch((err) => {
      console.log(err);
    });
};
getDataList();
const roomnumber = state.roomnumber;
const searchRoom = (roomnumber: any) => {
  RoomControllerService.searchRoomUsingPost(roomnumber)
    .then((res) => {
      let datas = res.data;
      state.dataList = datas;
    })
    .catch((err) => {
      console.log(err);
    });
};
const goSearch = () => {
  if (state.roomnumber != null) {
    searchRoom(state.roomnumber);
  }
};
goSearch();

// const godelete = (dada) => {
//   alert(dada);
//   // RoomControllerService.deleteRoomUsingPost(data)
//   //   .then((res) => {
//   //     message.success(res.data);
//   //   })
//   //   .catch((err) => {
//   //     console.log(err);
//   //   });
// };
const toEdit = (row: any) => {
  visible.value = true;
};
const handleOk = (form: any, row: any) => {
  form_a.toDorm = row.dormNumber;
  form_a.state = "正在审批";
  form_a.studentId = store.state.user?.loginUser.id;
  ApplyControllerService.addApplyUsingPost(form_a);
  getDataList();
};
const handleCancel = () => {
  visible.value = false;
};
</script>

<style>
#aboutView {
  margin-bottom: 10px;
  text-align: inherit;
}
</style>
